{
	let $time = $(".sub-title>span");

	let dateTimeFormat = new Intl.DateTimeFormat('zh-CN', {
		year: 'numeric',
		month: 'long',
		day: 'numeric',
		hour: 'numeric',
		minute: "numeric",
		second: "numeric",
		hour12: false
	});

	function setDateTime() {
		$time.html(dateTimeFormat.format(new Date()));
		setInterval(() => {
			$time.html(dateTimeFormat.format(new Date()));
		}, 1000);
	}
	setDateTime();

	$.fn.numberRock=function(options){
		let defaults={
			lastNumber:100,
			duration:5000,
			easing:'swing'
		};
		let opts=$.extend({}, defaults, options);
		$(this).animate({
			num : "numberRock",
		},{
			duration : opts.duration,
			easing : opts.easing,
			complete : function(){},
			step : function(a,b){
				$(this).html(parseInt(b.pos * opts.lastNumber));
			}
		});
	};
	
	function initEcharts( dom ){
		let temp = echarts.init( dom , "dark" );
		// temp.setOption({
		// })
		return temp;
	}

	// function loadDataForJSONP(name="disease_other"){
	// 	return $.ajax("https://view.inews.qq.com/g2/getOnsInfo",{
	// 		data:{
	// 			name
	// 		},
	// 		dataType:"jsonp"
	// 	}).promise();
	// }

	// 数值渲染
	let $confirm = $("#dataCount .number[type=confirm]");
	let $heal = $("#dataCount .number[type=heal]");
	let $dead = $("#dataCount .number[type=dead]");
	let $nowConfirm = $("#dataCount .number[type=nowConfirm]");
	let $noInfect = $("#dataCount .number[type=noInfect]");
	let $importedCase = $("#dataCount .number[type=importedCase]");

	// 图形渲染
	let loadingDefault = {
		text: '数据获取中……',
		textColor:"#fff",
		maskColor: 'rgba(0, 0, 0, 0)',
	}
	let $cov19map = $("#cov19-map");
	let $cov19cumulative = $("#cov19-cumulative");
	let $cov19new = $("#cov19-new");
	let $cov19provincialStatistics = $("#cov19-provincialStatistics");
	let $cov19outsideTheInput = $("#cov19-outsideTheInput");
	
	// 初始化 图形
	// let cov19mapChart = echarts.init( $cov19map[0] , "dark" );
	let cov19mapChart = initEcharts( $cov19map[0] );
	cov19mapChart.setOption({
		tooltip:{
			formatter:"{b}<br>累计确诊:{c}"
		},
		visualMap:[{
			type:"piecewise",
			text:["人数"],
			showLabel:true,
			textStyle:{
				color:"#fff"
			},
			bottom:"20px"
		}],
		series:[
			{ 
				type:"map",
				map:"china",
				label:{
					show:true,
					color:"#333"
				}
			}
		]
	});
	cov19mapChart.showLoading( Object.assign({},loadingDefault,{ textColor:"#000" }) );

	let cov19cumulative = initEcharts( $cov19cumulative[0] );
	cov19cumulative.showLoading(loadingDefault);

	let cov19new = initEcharts( $cov19new[0] )
	cov19new.showLoading(loadingDefault);

	let cov19provincialStatistics = initEcharts( $cov19provincialStatistics[0] )
	cov19provincialStatistics.setOption({
		legend: {},
		tooltip: {},
		dataset: {
			dimensions:["name","confirm","dead","heal"],
			source: []
		},
		xAxis: {
			type: 'category',
			axisLabel:{
				interval:0
			}
		},
		yAxis: {
			axisLabel:{
				formatter(v){
					let num = Number.parseInt(v/10000);
					return num > 0? num+"K":v;
				}
			}
		},
		series: [{ type: 'bar',name:"确诊" }, { type: 'bar',name:"死亡" }, { type: 'bar',name:"治愈" }]
	});
	cov19provincialStatistics.showLoading(loadingDefault);

	let cov19outsideTheInput = initEcharts( $cov19outsideTheInput[0] )
	cov19outsideTheInput.showLoading(loadingDefault);

	// 自动适配调整
	window.onresize = function(){
		cov19mapChart.resize();
		cov19cumulative.resize();
		cov19new.resize();
		cov19provincialStatistics.resize();
		cov19outsideTheInput.resize();
	}
	
	// 异步数据加载
	// get-jsonp请求:https://view.inews.qq.com/g2/getOnsInfo
	// 		    参数: name=disease_other   |    name=disease_h5
	// 			参数: callback=
	const URL = "https://view.inews.qq.com/g2/getOnsInfo";
	async function loadH5Data(){
		try {
			let { data } = await $.ajax(URL,{
				data:{
					name:"disease_h5"
				},
				dataType:"jsonp"
			});
			console.log(JSON.parse(data));
			let { areaTree:[ prov ] } = JSON.parse(data);

			// 构建地图的数据结果
			let mapData = [];
			// 省份数据统计构建
			let provData = [];
			prov.children.forEach( pItem => {
				mapData.push({
					name:pItem.name,
					value:pItem.total.confirm
				});
				provData.push({
					name:pItem.name,
					confirm:pItem.total.confirm,
					dead:pItem.total.dead,
					heal:pItem.total.heal
				});
			});
			// setOption 完成配置整合和刷新
			cov19mapChart.setOption({
				visualMap:[{
					pieces:[
						{min: 100000},
						{min: 10000, max: 100000},
						{min: 1000, max: 10000},
						{min: 100, max: 1000},
						{min: 0, max: 100}
					]
				}],
				series:[{ data:mapData }]
			});
			let proi = 4;
			let nowData = provData.slice(0,proi+1);
			cov19provincialStatistics.setOption({
				dataset: { source:nowData }
			})
			setInterval(()=>{
				if(proi>=provData.length){
					proi = 0;
				}else{
					proi+=1;
				}
				nowData.shift();
				nowData.push( provData[proi] )
				cov19provincialStatistics.setOption({
					dataset: { source:nowData }
				})
			},2000)
			
		} catch (error) {
			console.log("请求错误:",error)
		} finally {
			cov19mapChart.hideLoading();
			cov19provincialStatistics.hideLoading();
		}
	}
	loadH5Data();
}